// pages/shopping/activity/activity.js
var app = getApp();
var _PAGESIZE = 3;//默认页量
var _PAGE = 1;//默认页码
var cancelsOrder = false;//取消
Page({

  /**
   * 页面的初始数据
   */
  data: {
    activityBg: app.globalData._network_path + 'activity_bg.png',
    progressShow: false,//进度弹窗显示
    id: '',
    progressData: '',
    list: [],
    load_show: false,//是否请求过接口
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    _PAGE = 1;
    that.setData({
      list: [],
      load_show: false
    })
    that.getList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  //查看报单规则
  navRule(){
    wx.navigateTo({
      url: '/pages/shopping/rule/rule',
    })
  },
  //去报单
  navConfirm(){
    wx.navigateTo({
      url: '/pages/shopping/orderConfirm/orderConfirm',
    })
  },

  //取消订单
  cancelOrder(e) {
    var that = this;
    var id = e.currentTarget.dataset.id;
    wx.showModal({
      title: '提示',
      content: '是否取消该订单',
      confirmColor: '#c80000',
      success: function (res) {
        if (res.confirm) {
          // if (cancelsOrder) {
          //   return false
          // }
          // cancelsOrder = true;
          console.log(123)
          app.ajax({
            url: 'User/Order/cancelIdentificationTable',
            method: 'POST',
            data: {
              identification_id: id
            },
            success: function (res) {
              app.showToast(res.data.message);
              if (res.data.code == 1000) {
                var timer = setTimeout(function () {
                  that.getList();
                }, 1000)
              }
              // cancelsOrder = false;
            }
          })

        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  // 查看进度
  lookProgress(e) {
    var that = this;
    var id = e.currentTarget.dataset.id;
    that.setData({
      progressShow: true,
      progressData: [],
      id: id
    })
    app.ajax({
      url: 'User/Work/projectProgress',
      method: 'POST',
      data: {
        identification_id: id,
      },
      success: function (res) {
        if (res.data.code == 1000) {
          that.setData({
            progressData: res.data.data
          })
        }
      }
    })
  },
  // 关闭进度弹窗
  cancelModal: function () {
    var that = this;
    that.setData({
      progressShow: false,
      id: ''
    })
  },

  // 跳转订单详情
  goDetail(e) {
    var that = this;
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/user/myOrderDetail/myOrderDetail?id=' + id,
    })
  },
  //跳转更多记录
  lookMore(){
    wx.navigateTo({
      url: '/pages/user/myOrderList/myOrderList',
    })
  },
  // 已拒绝单重新编辑
  editOrder(e) {
    var that = this;
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/shopping/orderConfirm/orderConfirm?id=' + id + '&is_edit=true',
    })
  },
  // 跳转查看合同
  orderContract(e) {
    var that = this;
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/subpackage/pages/extend/contractList/contractList?id=' + id,
    })
  },

  //获取列表
  getList() {
    var that = this;
    app.ajax({
      url: 'User/Order/identification_info_list',
      method: "POST",
      msg: '加载中...',
      data: { page: _PAGE, pageSize: _PAGESIZE },
      success: function (res) {
        that.setData({
          load_show: true
        });
        if (res.data.code == 1000) {
          that.setData({
            list: res.data.data,
          });
        }
      }
    })
  },
})